﻿<%@ WebHandler Language="VB" Class="UploadDocumentFile" %>

Imports System
Imports System.Web
Imports System.Data
Imports Newtonsoft.Json
Imports System.Xml
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class UploadDocumentFile : Implements IHttpHandler
	
	Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
		Dim fileCol As HttpFileCollection = context.Request.Files
		Dim arr As String = ""
		Dim file As HttpPostedFile = fileCol(0)
		Dim relativePath As String = context.Server.MapPath("~/Uploads/")
		'Logic to find the FileName (excluding the path)
		If Not Directory.Exists(relativePath) Then
			Directory.CreateDirectory(relativePath)
		End If
		If (System.IO.File.Exists(relativePath + file.FileName)) Then
			System.IO.File.Delete(relativePath + file.FileName)
		End If
		context.Request.Files("fileAttach").SaveAs(relativePath + file.FileName)
		arr = file.FileName
		context.Response.Write(arr)
	End Sub
	
	Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
		Get
			Return False
		End Get
	End Property

End Class